package com.example.yue.zxinglibrarytest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import banding.com.google.Zxing.scanview.CaptureActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        View rootLayout = findViewById(R.id.rootLayout_main);
        listenExceptLayout(rootLayout);
    }

    private void listenExceptLayout(View view) {
            if (view instanceof ViewGroup) {//Android的布局继承自ViewGroup
                ViewGroup parent = (ViewGroup) view;
                for (int i = 0; i < parent.getChildCount(); i++) {
                    listenExceptLayout(parent.getChildAt(i));
                }
            } else {//如果不是一个布局，加入监听
                view.setClickable(true);//设为可点击
                view.setOnClickListener(this);
            }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        Class<? extends Activity> cls = CaptureActivity.class;
        Log.d(">>>",((Button)v).getText()+"");
        switch (v.getId()) {
            case R.id.btn_genCode:
                cls = GenCodeActivity.class;
                intent.setClass(this, cls);
                break;
            case R.id.btn_loadImage:
                cls = ImagesActivity.class;
                intent.setClass(this,cls);
                break;
            default :
                intent.setClass(this, cls);
                break;
        }
        startActivity(intent);
    }
}
